package Entities;

import Visitor.IVisitor;
import java.util.ArrayList;

public class Scene implements Entities.Drawable {
    private int id;

    private ArrayList<Drawable> drawableList;

    public Scene() {
        drawableList = new ArrayList<>();
    }

    @Override
    public Drawable accept(IVisitor visitor) {
        Drawable aux = null;
        synchronized (drawableList) {
            for (Drawable d : drawableList) {
                aux = d.accept(visitor);
                if (aux != null) {
                    return aux;
                }
            }
        }
        return null;
    }

    @Override
    public void addChild(Drawable drawable) {
        synchronized (drawableList) {
            drawableList.add(drawable);
        }
    }

    @Override
    public void remove(Drawable drawable) {
        synchronized (drawableList) {
            drawableList.remove(drawable);
        }
    }

    @Override
    public Drawable getChild(int pos) {
        synchronized (drawableList) {
            return drawableList.get(pos);
        }
    }

    @Override
    public int getNumElems() {
        return drawableList.size();
    }

    @Override
    public int getId() {
        return id;
    }

    @Override
    public void setId(int id) {
        this.id = id;
    }
}
